﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XmlCreate
{
    public partial class IOGROUPForm : Form
    {
        public IODEFIOGROUP IOGROUP = new IODEFIOGROUP();
        public IOGROUPForm(string _descFrombase, string _nameFrombase, IODEFIOGROUP _IOGROUP)
        {
            InitializeComponent();
            desctext.Text = _descFrombase;
            nametext.Text = _nameFrombase;
            if (!string.IsNullOrEmpty(_descFrombase))
            {
                desctext.ReadOnly = true;
            }

            if (!string.IsNullOrEmpty(_nameFrombase))
            {
                nametext.ReadOnly = true;
            }
            this.StartPosition = FormStartPosition.CenterScreen;

            if (_IOGROUP!=null&&_IOGROUP.TAG != null && _IOGROUP.name != null && _IOGROUP.name != null)
            {
                desctext.Text = _IOGROUP.desc;
                nametext.Text = _IOGROUP.name;
                for (int i = 0; i < _IOGROUP.TAG.Count; i++)
                {
                    tagDtv.Rows[i].Cells["DESC"].Value = _IOGROUP.TAG[i].DESC;
                    tagDtv.Rows[i].Cells["DT"].Value = _IOGROUP.TAG[i].DT;
                    tagDtv.Rows[i].Cells["HP"].Value = _IOGROUP.TAG[i].HP;
                    tagDtv.Rows[i].Cells["id"].Value = _IOGROUP.TAG[i].id;
                    tagDtv.Rows[i].Cells["LL"].Value = _IOGROUP.TAG[i].LL;
                    tagDtv.Rows[i].Cells["PN"].Value = _IOGROUP.TAG[i].PN;
                    tagDtv.Rows[i].Cells["UL"].Value = _IOGROUP.TAG[i].UL;
                }
            }
        }

        public string descFrombase;
        public string nameFrombase;
        private void CancelBtn_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void Okbtn_Click(object sender, EventArgs e)
        {
            IOGROUP.desc = desctext.Text;
            IOGROUP.name = nametext.Text;
            List<IODEFIOGROUPTAG> iODEFIOGROUPTAG = new List<IODEFIOGROUPTAG>();
            for (int i = 0; i < tagDtv.Rows.Count-1; i++)
            {
                iODEFIOGROUPTAG.Add(new IODEFIOGROUPTAG
                {
                    DESC = tagDtv.Rows[i].Cells["DESC"].Value.ToString(),
                    DT = tagDtv.Rows[i].Cells["DT"].Value.ToString(),
                    HP = tagDtv.Rows[i].Cells["HP"].Value.ToString(),
                    id = tagDtv.Rows[i].Cells["id"].Value.ToString(),
                    LL = tagDtv.Rows[i].Cells["LL"].Value.ToString(),
                    PN = tagDtv.Rows[i].Cells["PN"].Value.ToString(),
                    UL = tagDtv.Rows[i].Cells["UL"].Value.ToString()
                });
            }
           
            IOGROUP.TAG = iODEFIOGROUPTAG;
            DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
